import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        name: 'layout',
        meta: {
            title: '布局',
            hidden: true
        },
        redirect: '/newsList',
        component: () => import(/* webpackChunkName: "about" */ '../components/Layout/Layout_index.vue'),
        children: [
            {
                path: 'newsList',
                name: 'newsList',
                meta: {
                    title: '新闻列表',
                    icon: require('@/assets/newList.png'),
                    iconSel: require('@/assets/newList_sel.png')
                },
                component: () => import(/* webpackChunkName: "about" */ '../views/newsList.vue')
            },
            {
                path: 'newsType',
                name: 'newsType',
                meta: {
                    title: '新闻分类',
                    icon: require('@/assets/newType.png'),
                    iconSel: require('@/assets/newType_sel.png')
                },
                beforeEnter: (to, from, next) => {
                    // console.log("即将进入新闻分类的页面");
                    next()
                    // ...
                },
                component: () => import(/* webpackChunkName: "about" */ '../views/newsType.vue')
            },
            {
                path: 'newUsers',
                name: 'newUsers',
                meta: {
                    title: '用户管理',
                    icon: require('@/assets/newUsers.png'),
                    iconSel: require('@/assets/newUsers_sel.png')
                },
                component: () => import(/* webpackChunkName: "about" */ '../views/newUsers.vue')
            },
            {
                path: "swiperMgr",
                name: "swiperMgr",
                meta: {
                    title: "轮播图管理",
                    icon: require('@/assets/swiper.png'),
                    iconSel: require('@/assets/swiper_sel.png')
                },
                component: () => import(/* webpackChunkName: "about" */ '../views/swiperMgr.vue')
            },
        ],
    },
    {
        path: "/newLogin",
        name: "newLogin",
        meta: {
            title: "登录",
            hidden: true
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/newLogin.vue')
    }
]


const router = new VueRouter({
    routes
})

// 每一次路由跳转前
router.beforeEach((to, from, next) => {
    // console.log("路由跳转前");
    // 修改页面的title
    document.title = to.meta.title
    // 判断用户是否登录，如果登录了正常跳转，如果没有登录，那么跳转登录页面
    // if(localStorage.getItem("token")){
    //   next()
    // }else{
    //   next("/login")
    // }
    next()
})


export default router